<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" class="tl-dialog page" width="1000px" @open="open" @close="close" top="50px" :append-to-body="true" :modal-append-to-body="true">
    <div style="padding-bottom:10px">
      <!-- 列表界面 -->
      <div>
        <!-- 列表选择 -->
        <div class="table-alert-div" ref="selector">
          <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
            <template slot="title">
              已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRows.length }}</a
              >项&nbsp;&nbsp;
              <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
            </template>
          </el-alert>
        </div>
        <!--表格渲染-->
        <el-table class="tl-table" ref="mainTable" :height="tableHeight" v-loading="loading" :data="page" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
          <el-table-column type="selection" width="55px" fixed="left" v-if="isSingleSelect === false"> </el-table-column>
          <template v-if="title === '选择线索'">
            <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
            <el-table-column prop="code" label="线索编号" width="200px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="name" label="线索名称" min-width="200px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="ourprocductfund" label="可参与金额（万元）" width="150px" align="right" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="clientname" label="客户名称" width="200px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="gardenername" label="负责人" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="createtime" label="创建时间" width="150px" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="displeadstatus" label="线索状态" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
          </template>
          <template v-else-if="title === '选择机会点'">
            <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
            <el-table-column prop="code" label="机会点编号" width="200px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="name" label="机会点名称" min-width="200px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="ourprocductfund" label="可参与金额（万元）" width="150px" align="right" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="clientname" label="客户名称" width="200px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="gardenername" label="负责人" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="createtime" label="创建时间" width="150px" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="dispchancestatus" label="机会点状态" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
          </template>
          <template v-else-if="title === '选择合同'">
            <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
            <el-table-column prop="category" label="单据类型" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="docno" label="单据编号" width="200px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="name" label="合同/采购单名称" min-width="200px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="contractmoney" label="合同/采购单金额（元）" width="170px" align="right" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="customername" label="客户名称" width="200px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="dispwhetherframeworkaggrement" label="是否框架" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="username" label="申请人" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="docdate" label="申请日期" width="150px" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="dispcontractstate" label="合同/采购单状态" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
          </template>
          <template v-else-if="title === '选择投标'">
            <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
            <el-table-column prop="docno" label="单据编号" width="150px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="name" label="项目名称" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="fund" label="可参与金额（万元）" width="150px" align="right" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="dispprojectlevel" label="项目级别" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="gardener_name" label="项目经理" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="docdate" label="单据时间" width="150px" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="dispstate" label="单据状态" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
          </template>
          <template v-else-if="title === '选择销售项目'">
            <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
            <el-table-column prop="projectcode" label="项目编号" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="name" label="项目名称" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="participatemoney" label="可参与金额（万元）" width="150px" align="right" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="dispprojectlevel" label="项目级别" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="projectmanager" label="项目经理" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="finishdate" label="立项时间" width="150px" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="dispprojectstate" label="项目阶段" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
          </template>
          <template v-else-if="title === '选择虚线索'">
            <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
            <el-table-column prop="docno" label="虚线索编号" width="150px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="name" label="虚线索名称" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="fund" label="总金额（万元）" width="150px" align="right" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="username" label="负责人" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="createtime" label="发布时间" width="150px" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="dispvagueleadstatus" label="虚线索状态" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
          </template>
          <template v-else>
            <el-table-column prop="name" label="名称" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
          </template>
          <el-table-column label="操作" width="80px" align="center" fixed="right" v-if="isSingleSelect === true">
            <template slot-scope="scope">
              <el-tooltip effect="dark" :disabled="scope.row.viewable" content="没有访问权限" placement="left">
                <div style="width:100%">
                  <el-button :disabled="!scope.row.viewable" type="text" icon="el-icon-finished" @click="doSelectData(scope.row[fieldDefaultKey])">选择</el-button>
                </div>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <!-- 列表分页 -->
        <el-row class="pagebar" ref="pager">
          <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
        </el-row>
      </div>
    </div>
    <div slot="footer" class="dialog-footer" v-if="isSingleSelect === false">
      <el-button type="text" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doConfirm">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_ref_list } from '@tapui/mixins/mixin_ref_list'
/** 子组件 */
/** 工具类 */
/** VUE配置 */
export default {
  name: 'navRefList',
  components: {},
  mixins: [mixin_ref_list],
  data() {
    return {
      description: '侧边导航栏参照页面',
      // 默认表格高度
      tableHeight: '425px',
      // 排序参数
      sorterInfo: {
        sidx: 'name',
        sord: 'asc'
      }
    }
  },
  props: {
    navDatas: {
      type: Array,
      default: () => []
    }
  },
  computed: {
    page() {
      const startIndex = (this.pageInfo.currentPage - 1) * this.pageInfo.pageSize
      const endIndex = this.pageInfo.currentPage * this.pageInfo.pageSize <= this.datas.length ? this.pageInfo.currentPage * this.pageInfo.pageSize : this.datas.length
      return this.datas.slice(startIndex, endIndex)
    }
  },
  methods: {
    loadData() {
      this.datas = [...this.navDatas].sort((a, b) => {
        if (!a.viewable && b.viewable) return 1
        else if (a.viewable && !b.viewable) return -1
        else return 0
      })
      this.pageInfo.totalCount = this.datas.length
    },
    /** 表格双击事件 */
    doRowDbClick(row, column, event) {
      if (!row.viewable) {
        this.$tap.alert('没有访问权限')
        return
      }
      this.doSelectData(row[this.fieldKeyComputed])
    },
    /** 表格多选行选中样式*/
    doChangeRowClassName({ row, rowIndex }) {
      if (!row.viewable) {
        return 'row-disabled'
      }
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/ .el-table {
  tr.row-disabled {
    color: #c0c4cc;
  }
}
.tl-dialog {
  /deep/ .el-dialog .el-dialog__body {
    padding: 10px 20px !important;
  }
  /deep/ .el-table {
    .el-table__body,
    .el-table__footer,
    .el-table__header {
      border-left: none;
    }
    td,
    th.is-leaf {
      border-bottom: 1px solid #ebeef5 !important;
    }
    th {
      border-top: none !important;
    }
    thead th {
      background-color: #fafafa;
    }
  }
  /deep/ .el-table--border {
    td,
    th {
      border-right: 1px solid #ebeef5 !important;
    }
  }
  /deep/ .el-table__body-wrapper .el-table--border.is-scrolling-left ~ .el-table__fixed {
    border-right: 1px solid #ebeef5 !important;
  }
}
body[data-display-mode='projector'] .tl-dialog {
  /deep/ .el-table {
    td,
    th.is-leaf {
      border-bottom: 1px solid #a0a0a0 !important;
    }
  }
  /deep/ .el-table--border {
    td,
    th {
      border-right: 1px solid #a0a0a0 !important;
    }
  }
  /deep/ .el-table__body-wrapper .el-table--border.is-scrolling-left ~ .el-table__fixed {
    border-right: 1px solid #a0a0a0 !important;
  }
}
</style>
